import com.itheima.sdk.WXPay;
import com.itheima.utils.MyWXPayConfigImpl;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 吴
 * @version V1.0
 * @Description   测试
 * @Package com.github.wxpay.controller
 * @date 2021/12/9 13:34
 */
public class WXPayExample {

        @Test
        public void unifiedOrder() throws Exception {
                MyWXPayConfigImpl config = new MyWXPayConfigImpl();
                WXPay wxpay = new WXPay(config);
                // 订单号
                String  orderNumber = UUID.randomUUID().toString().replace("-", "");
                System.out.println(orderNumber);
                // 结束时间
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                calendar.add(Calendar.MINUTE,1);
                String format = new SimpleDateFormat("yyyyMMddHHmmss").format(calendar.getTime());
                System.out.println(format);

                Map<String, String> data = new HashMap<String, String>();
                data.put("body", "测试");
                data.put("out_trade_no", orderNumber);
                data.put("fee_type", "CNY");
                data.put("total_fee", "1");
                data.put("spbill_create_ip", "123.12.12.123");
                data.put("notify_url", "http://rcrcyp.natappfree.cc/wxpay/notify");
                data.put("trade_type", "NATIVE");  // 此处指定为扫码支付
                data.put("product_id", "12");
                data.put("time_expire",format);
                try {
                    Map<String, String> resp = wxpay.unifiedOrder(data);
                    System.out.println(resp);
                    System.out.println(resp.get("code_url"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }

    @Test
    public void orderQuery() throws Exception {
            MyWXPayConfigImpl config = new MyWXPayConfigImpl();
            WXPay wxpay = new WXPay(config);

            Map<String, String> data = new HashMap<String, String>();
            data.put("out_trade_no", "defd9325cf914bb983592d9208dabf9d");
            try {
            Map<String, String> resp = wxpay.orderQuery(data);
                    System.out.println(resp.get("trade_state_desc"));
            System.out.println(resp);
            } catch (Exception e) {
                    e.printStackTrace();
            }
    }
}
